//
//  BVModifyNameViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/10/21.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVModifyNameViewController.h"

@interface BVModifyNameViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@end

@implementation BVModifyNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"我的姓名"];
    [self setupRightBarButtonItem];
    [self.navItem setEnabled:NO];
    [self.navItem setTitleColor:[UIColor BVLineGrayColor] forState:UIControlStateNormal];}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.nameTextField setPlaceholder:self.user.name.length == 0 ? @"您的姓名" : self.user.name];
}

#pragma mark -
#pragma mark - save
- (void)confirmSaveClick {
    [self.hud show:YES];
    [JDStatusBarNotification showWithStatus:@"正在保存" styleName:JDStatusBarStyleDefault ];
    [self.mineTool modifyUserName:self.nameTextField.text success:^{
        [self.hud hide:YES];
        [JDStatusBarNotification showWithStatus:@"保存成功" dismissAfter:2.0 styleName:JDStatusBarStyleSuccess];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [self.hud hide:YES];
        [self showError:@"保存失败"];
    }];
}

- (IBAction)textFieldChange:(UITextField *)textField {
    if ([textField.text isEqualToString:self.user.name] || textField.text.length == 0) {
        [self.navItem setEnabled:NO];
        [self.navItem setTitleColor:[UIColor BVLineGrayColor] forState:UIControlStateNormal];
    } else {
        [self.navItem setEnabled:YES];
        [self.navItem setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
}

- (IBAction)tap:(id)sender {
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
